package edu.uwm.cs552;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Polygon;

/**
 * @author boyland
 *
 */
public enum Terrain implements Topography<Terrain> {
	TERASE, PLAIN, DESERT, MOUNTAIN, WATER, SMALL, MEDIUM, LARGE, SUBURB; 

	public static final Color WATER_COLOR = new Color(0x75,0xC5,0xF0);
	private static int[] x = {0,0,0}, y = {0,0,0};

	/*
	 * We considered making this abstract, but the Java syntax
	 * was TOO verbose.
	 */
	/* (non-Javadoc)
	 * @see edu.uwm.cs552.Topography#draw(java.awt.Graphics, edu.uwm.cs552.HexCoordinate, double)
	 */
	@Override
	public void draw(Graphics g, HasTopography<Terrain> h, double scale, boolean showHidden) {
		Point p = h.toPoint(scale);
		// if the scale is small, big dots are too big
		int dotsize = scale <= 10.0 ? 1 : scale < 50 ? 3 : 5;
		int less = dotsize / 2;
		switch (this) {
		case PLAIN:
		case MOUNTAIN:
			g.setColor(Color.BLACK); 
			break;
		case SUBURB:
			if(showHidden)
				g.setColor(Color.MAGENTA);
			else
				g.setColor(Color.BLACK); 
			break;
		case DESERT:
			g.setColor(new Color(0xff,0xde,0xad)); // Navajo White
			dotsize += 2;
			less += 1;
			break;
		case WATER:
			g.setColor(WATER_COLOR);
			break;
		case SMALL:
		case MEDIUM:
		case LARGE:
			g.setColor(Color.RED);
			break;
		}
		switch (this) {
		case MEDIUM:
		{
			int s = (int)(scale/2.0)&~1;
			g.fillRect(p.x-s/2,p.y-s/2,s,s);
			g.setColor(Color.BLACK);
		}
		// fallthrough
		case PLAIN:
		case DESERT:
		case SUBURB:
			g.fillRect(p.x-less, p.y-less, dotsize, dotsize);
			break;
		case SMALL: {
			int s = (int)(scale/2.0)&~1;
			g.fillOval(p.x-s/2,p.y-s/2,s,s);
			g.setColor(Color.BLACK);
			g.fillRect(p.x-less, p.y-less, dotsize, dotsize);
		}
		break;
		case MOUNTAIN:
		{
			int off = (int)(scale/4);
			x[0] = p.x-off; x[1] = p.x;     x[2] = p.x+off;
			y[0] = p.y+off; y[1] = p.y-off; y[2] = p.y+off;
			g.fillPolygon(x, y, 3);
			/*
      g.drawLine(p.x-off, p.y+off, p.x, p.y-off);
      if (scale >= 20) g.drawLine(p.x-off+1, p.y+off, p.x, p.y-off+1);
      g.drawLine(p.x, p.y-off, p.x+off, p.y+off);
      if (scale >= 20) g.drawLine(p.x, p.y-off+1, p.x+off-1, p.y+off);*/
		}
		break;
		case LARGE:
		{
			Polygon hex = new Polygon();
			for (HexDirection d : HexDirection.values()) {
				Point pt = h.move(d).toPoint(scale);
				hex.addPoint(pt.x, pt.y);
			}
			g.fillPolygon(hex);
			g.setColor(Color.BLACK);
			g.fillRect(p.x-less, p.y-less, dotsize, dotsize);
		}
		break;
		case WATER:
			g.fillPolygon(h.toPolygon(scale));
			break;
		}
	}

	@Override
	public HasTopography<Terrain> getOrigin() {
		return HexCoordinate.ORIGIN;
	}
}
